package com.game.center.respository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.game.center.AbstractDao;
import com.game.center.entity.Player;
import com.game.center.redis.EnumRedisKey;
import com.game.center.mapper.PlayerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author 林道敬
 * @Date 2023-07-30
 * @Description
 **/
@Component
public class PlayerRespository extends AbstractDao<Player> {

    @Autowired
    private PlayerMapper playerMapper;

    @Override
    protected EnumRedisKey getRedisKey() {
        return EnumRedisKey.PLAYER_INFO;
    }

    @Override
    protected Class<Player> getEntityClass() {
        return Player.class;
    }

    @Override
    protected BaseMapper<Player> getRepository() {
        return playerMapper;
    }

    @Override
    protected void saveOrUpdateToDB(Player player) {
        if(player != null){
            if(player.getPlayerId()==null){
                playerMapper.insert(player);
            }else {
                playerMapper.updateById(player);
            }
        }
    }
}
